package com.ktvme.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktvme.dto.ClusterDTO;
import com.ktvme.entity.Cluster;
import com.ktvme.mapper.ClusterMapper;
import com.ktvme.service.ClusterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class ClusterServiceImpl extends ServiceImpl<ClusterMapper, Cluster> implements ClusterService {
    private final ClusterMapper clusterMapper;

    public ClusterServiceImpl(ClusterMapper clusterMapper) {
        this.clusterMapper = clusterMapper;
    }

    @Override
    public void save(ClusterDTO clusterDTO) {
        Cluster cluster = new Cluster();
        BeanUtils.copyProperties(clusterDTO,cluster);
        log.info("新增集群：{}",clusterDTO);
        clusterMapper.insert(cluster);
    }

    @Override
    public void delete(String clusterId) {
        clusterMapper.delete(clusterId);
        log.info("删除集群：{}",clusterId);
    }

    @Override
    public void update(ClusterDTO clusterDTO,Integer clusterId) {
        Cluster cluster = new Cluster();
        BeanUtils.copyProperties(clusterDTO,cluster);
        cluster.setId(clusterId);
        log.info("clusterId:{},clusterDTO：{},cluster:{}",clusterId,clusterDTO,cluster);
        clusterMapper.updateById(cluster);
    }
}
